const BASE_URL = 'https://tea.qingnian8.com/api/bizhi'
export const request = (config = {}) => {
	let {
		url,
		method = "GET",
		data = {},
		header = {}
	} = config
	header['access-key'] = ''
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '加载中...'
		})
		uni.request({
			url: BASE_URL + url,
			method,
			data,
			header,
			dataType: 'json',
			success: (res) => {
				uni.hideLoading()
				if (res.data.errCode == 0) {
					resolve(res.data)
				} else if (res.data.errCode == 400) {
					uni.showModal({
						title: '提示',
						content: res
						.data
						.errMsg,
						icon: 'none',
						showCancel: false
					})
					reject(res.data)
				} else {
					uni.showToast({
						title: '错误提示',
						content: res
						.data
						.errMsg,
						icon: 'none'
					})
					reject(res.data)
				}

			},
			fail: (err) => {
				uni.showToast({
					title: '错误提示',
					content: err,
					icon: 'none'
				})
				reject(err)
			}
		})
	})
}